package com.spring.demo2;

import org.junit.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import java.util.Arrays;

/**
 * @author vhans
 */
public class ConfigurationTest {
    @Test
    public void test1() {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ConfigBean.class);
        for (String beanName : context.getBeanDefinitionNames()) {
            String[] aliases = context.getAliases(beanName);
            System.out.printf("bean对象:%s,%n bean名称:%s,bean别名:%s%n",
                    context.getBean(beanName), beanName, Arrays.asList(aliases));
        }
    }

    @Test
    public void test2() {
        // 去掉@Configuration后,@Bean仍然生效,只是NoConfigBean类不在被cglib处理
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(NoConfigBean.class);
        for (String beanName : context.getBeanDefinitionNames()) {
            String[] aliases = context.getAliases(beanName);
            System.out.printf("bean对象:%s,%n bean名称:%s,bean别名:%s%n",
                    context.getBean(beanName), beanName, Arrays.asList(aliases));
        }
    }
}
